package huq.com.io;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * Output strings into unicode .txt file 
 * @author Qian
 *
 */
public class QOutUnicode {
	OutputStreamWriter bw;
	String outfile;
	
	public void open(String filename, String unicode){
		/**
		 * open the output stream
		 */
		outfile = filename;
		try{
			FileOutputStream fos=new FileOutputStream(outfile);
			bw=new OutputStreamWriter(fos, unicode); 
		}
		catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public void open(String filename, String unicode, boolean T){
		/**
		 * open the output stream, whether to append
		 */
		outfile = filename;
		try{
			FileOutputStream fos=new FileOutputStream(outfile,T);
			bw=new OutputStreamWriter(fos,"Unicode"); 
		}
		catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public void close(){
		/**
		 * close the output stream
		 */
		try{
			bw.close();
		}
		catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public void flush(){
		/**
		 * flush
		 */
		try{
			bw.flush();
		}
		catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public void write(String str){
		/**
		 * output a new Line into file
		 */
		try{
			bw.write(str);
		}
		catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public static void print(String str){
		System.out.print(str);
	}
	
	public static void println(String str){
		System.out.println(str);
	}
	
	public static void printf(String str){
		System.out.printf(str);
	}
}
